﻿package view
{
    import __AS3__.vec.*;
    import com.greensock.*;
    import flash.display.*;

    public class AttributeRun extends Sprite
    {
        private var attrArrs:Array;
        private var showArr:Vector.<AttributeCell>;
        private var timeLiteAdd:TimelineLite;

        public function AttributeRun()
        {
            this.attrArrs = [];
            this.showArr = new Vector.<AttributeCell>;
            return;
        }// end function

        public function init(param1:DisplayObjectContainer, param2:int, param3:int) : void
        {
            if (!this.parent)
            {
                param1.addChild(this);
            }
            this.x = param2;
            this.y = param3;
            return;
        }// end function

        public function checkAbi(param1:Object, param2:Object) : void
        {
            var _loc_4:String = null;
            var _loc_5:int = 0;
            var _loc_6:int = 0;
            var _loc_7:int = 0;
            var _loc_8:Object = null;
            var _loc_3:Array = [];
            for (_loc_4 in param1)
            {
                
                _loc_6 = 0;
                if (_loc_4 == "phyAtt" || _loc_4 == "phyDef" || _loc_4 == "magicAtt" || _loc_4 == "magicDef" || _loc_4 == "taoAtt")
                {
                    _loc_6 = param1[_loc_4] / Math.pow(2, 32) - param2[_loc_4] / Math.pow(2, 32);
                }
                else
                {
                    _loc_6 = param1[_loc_4] - param2[_loc_4];
                }
                if (_loc_6 == 0)
                {
                    continue;
                }
                switch(_loc_4)
                {
                    case "maxHp":
                    {
                        _loc_3.push({type:"sm", dis:_loc_6, index:"1"});
                        break;
                    }
                    case "maxMp":
                    {
                        _loc_3.push({type:"mf", dis:_loc_6, index:"2"});
                        break;
                    }
                    case "phyAtt":
                    {
                        _loc_3.push({type:"wg", dis:_loc_6, index:"3"});
                        break;
                    }
                    case "magicAtt":
                    {
                        _loc_3.push({type:"mg", dis:_loc_6, index:"4"});
                        break;
                    }
                    case "taoAtt":
                    {
                        _loc_3.push({type:"dg", dis:_loc_6, index:"5"});
                        break;
                    }
                    case "phyDef":
                    {
                        _loc_3.push({type:"wf", dis:_loc_6, index:"6"});
                        break;
                    }
                    case "magicDef":
                    {
                        _loc_3.push({type:"ff", dis:_loc_6, index:"7"});
                        break;
                    }
                    case "attackSpeed":
                    {
                        _loc_3.push({type:"gs", dis:_loc_6, index:"8"});
                        break;
                    }
                    case "accurate":
                    {
                        _loc_3.push({type:"mz", dis:_loc_6, index:"9"});
                        break;
                    }
                    case "luck":
                    {
                        _loc_3.push({type:"xy", dis:_loc_6, index:"10"});
                        break;
                    }
                    case "heathRecover":
                    {
                        _loc_3.push({type:"zd", dis:_loc_6, index:"11"});
                        break;
                    }
                    case "magicRecover":
                    {
                        _loc_3.push({type:"hl", dis:_loc_6, index:"12"});
                        break;
                    }
                    default:
                    {
                        break;
                    }
                }
            }
            _loc_5 = _loc_3.length - 2;
            while (_loc_5 >= 0)
            {
                
                _loc_7 = 0;
                while (_loc_7 <= _loc_5)
                {
                    
                    if (int(_loc_3[_loc_7].index) > int(_loc_3[(_loc_7 + 1)].index))
                    {
                        _loc_8 = _loc_3[_loc_7];
                        _loc_3[_loc_7] = _loc_3[(_loc_7 + 1)];
                        _loc_3[(_loc_7 + 1)] = _loc_8;
                    }
                    _loc_7++;
                }
                _loc_5 = _loc_5 - 1;
            }
            this.attrArrs.push(_loc_3);
            if (this.attrArrs.length > 2)
            {
                this.attrArrs.shift();
            }
            if (this.timeLiteAdd == null)
            {
                this.doShow();
            }
            return;
        }// end function

        private function doShow() : void
        {
            var _loc_1:AttributeCell = null;
            var _loc_2:Object = null;
            var _loc_5:Object = null;
            var _loc_6:int = 0;
            var _loc_7:Number = NaN;
            if (this.attrArrs.length == 0)
            {
                return;
            }
            var _loc_3:* = this.attrArrs.shift();
            if (_loc_3.length == 0)
            {
                this.doShow();
                return;
            }
            var _loc_4:int = 175;
            for each (_loc_5 in _loc_3)
            {
                
                _loc_1 = new AttributeCell(_loc_5);
                _loc_1.y = _loc_4;
                _loc_1.alpha = 0;
                _loc_1.scaleY = 0;
                this.addChild(_loc_1);
                _loc_4 = _loc_4 + 35;
                this.showArr.push(_loc_1);
            }
            this.timeLiteAdd = new TimelineLite();
            _loc_6 = 0;
            while (_loc_6 < this.showArr.length)
            {
                
                _loc_1 = this.showArr[_loc_6];
                _loc_2 = {y:_loc_1.y - 150, alpha:1, scaleY:1};
                this.timeLiteAdd.append(new TweenLite(_loc_1, 0.4, _loc_2), -0.2);
                _loc_6++;
            }
            _loc_6 = 0;
            while (_loc_6 < this.showArr.length)
            {
                
                _loc_1 = this.showArr[_loc_6];
                _loc_7 = -0.1;
                _loc_2 = {x:100, alpha:0, scaleY:0};
                if (_loc_6 == 0)
                {
                    _loc_7 = 1 - this.showArr.length * 0.1;
                }
                if (_loc_6 == (this.showArr.length - 1))
                {
                    _loc_2.onComplete = this.removeComplete;
                }
                this.timeLiteAdd.append(new TweenLite(_loc_1, 0.2, _loc_2), _loc_7);
                _loc_6++;
            }
            return;
        }// end function

        public function removeComplete() : void
        {
            var _loc_1:AttributeCell = null;
            this.timeLiteAdd.kill();
            this.timeLiteAdd = null;
            while (this.showArr.length > 0)
            {
                
                _loc_1 = this.showArr.shift();
                this.removeChild(_loc_1);
                _loc_1.destory();
                _loc_1 = null;
            }
            this.doShow();
            return;
        }// end function

    }
}
